libobs_wrapper\utils\info/
startup.rs1use crate::{
2 context::{ObsContext, ObsContextReturn}, data::{audio::ObsAudioInfo, video::ObsVideoInfo}, logger::{ConsoleLogger, ObsLogger}, utils::{ObsError, ObsPath, ObsString}
3};
4
5#[derive(Debug)]
8pub struct StartupInfo {
9 #[cfg(feature = "bootstrapper")]
10 pub(crate) bootstrap_handler: Option<Box<dyn crate::bootstrap::status_handler::ObsBootstrapStatusHandler>>,
11 #[cfg(feature = "bootstrapper")]
12 pub(crate) bootstrapper_options: crate::bootstrap::ObsBootstrapperOptions,
13
14 pub(crate) startup_paths: StartupPaths,
15 pub(crate) obs_video_info: ObsVideoInfo,
16 pub(crate) obs_audio_info: ObsAudioInfo,
17 pub(crate) logger: Option<Box<dyn ObsLogger + Sync + Send>>,
19}
20
21impl StartupInfo {
22 pub fn new() -> StartupInfo {
23 Self::default()
24 }
25
26 pub fn set_startup_paths(mut self, paths: StartupPaths) -> Self {
27 self.startup_paths = paths;
28 self
29 }
30
31 pub fn set_video_info(mut self, ovi: ObsVideoInfo) -> Self {
32 self.obs_video_info = ovi;
33 self
34 }
35
36 pub fn set_logger(mut self, logger: Box<dyn ObsLogger + Sync + Send>) -> Self {
37 self.logger = Some(logger);
38 self
39 }
40
41 #[cfg(feature = "bootstrapper")]
42 pub fn enable_bootstrapper<T>(
43 mut self,
44 handler: T,
45 options: crate::bootstrap::ObsBootstrapperOptions,
46 ) -> Self
47 where
48 T: crate::bootstrap::status_handler::ObsBootstrapStatusHandler + 'static,
49 {
50 self.bootstrap_handler = Some(Box::new(handler));
51 self.bootstrapper_options = options;
52 self
53 }
54
55 #[cfg_attr(feature="blocking", remove_async_await::remove_async_await)]
56 pub async fn start(self) -> Result<ObsContextReturn, ObsError> {
57 ObsContext::new(self).await
58 }
59}
60
61impl Default for StartupInfo {
62 fn default() -> StartupInfo {
63 Self {
64 startup_paths: StartupPaths::default(),
65 obs_video_info: ObsVideoInfo::default(),
66 obs_audio_info: ObsAudioInfo::default(),
67 logger: Some(Box::new(ConsoleLogger::new())),
68 #[cfg(feature = "bootstrapper")]
69 bootstrap_handler: None,
70
71 #[cfg(feature = "bootstrapper")]
72 bootstrapper_options: Default::default()
73 }
74 }
75}
76
77#[derive(Clone, Debug)]
84pub struct StartupPaths {
85 libobs_data_path: ObsString,
86 plugin_bin_path: ObsString,
87 plugin_data_path: ObsString,
88}
89
90impl StartupPaths {
91 pub fn new(
92 libobs_data_path: ObsPath,
93 plugin_bin_path: ObsPath,
94 plugin_data_path: ObsPath,
95 ) -> StartupPaths {
96 Self {
97 libobs_data_path: libobs_data_path.build(),
98 plugin_bin_path: plugin_bin_path.build(),
99 plugin_data_path: plugin_data_path.build(),
100 }
101 }
102
103 pub fn libobs_data_path(&self) -> &ObsString {
104 &(self.libobs_data_path)
105 }
106
107 pub fn plugin_bin_path(&self) -> &ObsString {
108 &(self.plugin_bin_path)
109 }
110
111 pub fn plugin_data_path(&self) -> &ObsString {
112 &(self.plugin_data_path)
113 }
114}
115
116impl Default for StartupPaths {
117 fn default() -> Self {
118 StartupPathsBuilder::new().build()
119 }
120}
121
122#[derive(Clone, Debug)]
123pub struct StartupPathsBuilder {
124 libobs_data_path: ObsPath,
125 plugin_bin_path: ObsPath,
126 plugin_data_path: ObsPath,
127}
128
129impl StartupPathsBuilder {
130 fn new() -> Self {
131 Self {
132 libobs_data_path: ObsPath::from_relative("data/libobs"),
133 plugin_bin_path: ObsPath::from_relative("obs-plugins/64bit"),
134 plugin_data_path: ObsPath::from_relative("data/obs-plugins/%module%"),
135 }
136 }
137
138 pub fn build(self) -> StartupPaths {
139 StartupPaths {
140 libobs_data_path: self.libobs_data_path.build(),
141 plugin_bin_path: self.plugin_bin_path.build(),
142 plugin_data_path: self.plugin_data_path.build(),
143 }
144 }
145
146 pub fn libobs_data_path(mut self, value: ObsPath) -> Self {
147 self.libobs_data_path = value;
148 self
149 }
150
151 pub fn plugin_bin_path(mut self, value: ObsPath) -> Self {
152 self.plugin_bin_path = value;
153 self
154 }
155
156 pub fn plugin_data_path(mut self, value: ObsPath) -> Self {
157 self.plugin_data_path = value;
158 self
159 }
160}
161
162impl Default for StartupPathsBuilder {
163 fn default() -> StartupPathsBuilder {
164 Self::new()
165 }
166}